package asruby.runtime
{
import asruby.Ruby;
import asruby.lang.RubyProc;	
public class GlobalVariable
{
  	private var accessor: IAccessor;
    private var traces: Array = null;
    private var tracing: Boolean;
	private var iRubyObject:IRubyObject = null;
	private var name:String;
    public function  GlobalVariable(accessor: IAccessor) {
        this.accessor = accessor;
    }
    
    public static function  newUndefined(runtime: Ruby, name: String): GlobalVariable {
        var variable: GlobalVariable = new GlobalVariable(null);
        //variable.setAccessor(new UndefinedAccessor(runtime, variable, name));
        return variable;
    }

    public function  getAccessor(): IAccessor {
        return accessor;
    }

    public function  getTraces(): Array {
        return traces;
    }

    public function  addTrace(command: RubyProc): void {
        if (traces == null) {
            traces = new Array();
        }
        traces.add(command);
    }

    public function  removeTrace(command: IRubyObject): Boolean {
        if (traces == null || !traces.contains(command)) {
            return false;
        }
        traces.remove(command);
        return true;
    }

    public function  removeTraces(): void {
        traces = null;
    }

    public function  setAccessor(accessor: IAccessor): void {
        this.accessor = accessor;
    }
    public function  isTracing(): Boolean {
        return tracing;
    }
    
    public function  trace(value: IRubyObject): void {
/*         if (traces == null) return;
        
        var context: ThreadContext = value.getRuntime().getCurrentContext();
        
        if (context.isWithinTrace()) return;
        
        try {
            context.setWithinTrace(true);

            for (var i: int = 0; i < traces.size(); i++) {
                ((RubyProc)traces.get(i)).call(context, new IRubyObject[] {value});
            }
        } finally {
            context.setWithinTrace(false);
        } */
    }
	public function getVal():IRubyObject{
		return this.iRubyObject;
	}
	public function setVal(iRubyObject: IRubyObject):IRubyObject{
		this.iRubyObject=iRubyObject;
		return this.getVal();
	}
	public function getName():String{
		return this.name;
	}
	public function setName(name:String):void{
		this.name=name;
	}
}
}